﻿using System;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace RedRiver.Framework.Web.UI{
    /// <summary>
    /// 集成样式基础页面
    /// </summary>
    public class ThemedPage : Page{
        /// <summary>
        /// 模板中内容占位控件ID
        /// </summary>
        private const string ContentPlaceHolderControlId = "ContentPlaceHolder";

        /// <summary>
        /// Profile 的 连接字符串组名称
        /// </summary>
        private const string ProfileConnectionStrings = "ConnectionStrings";

        /// <summary>
        /// Profile 的 主题项 
        /// </summary>
        private const string ProfileThemeName = "Theme";

        protected string SessionTheme{
            get { return Context.Profile[ProfileThemeName].ToString(); }
            set{
                if (!string.IsNullOrEmpty(value)){
                    Context.Profile[ProfileThemeName] = value;
                }
            }
        }

        /// <summary>
        /// 模板中的内容占位控件
        /// </summary>
        public virtual ContentPlaceHolder ContentPlaceHolder{
            get { return (ContentPlaceHolder) Page.Form.FindControl(ContentPlaceHolderControlId); }
        }

        protected string GetConnectionStrings(string connName){
            return Context.Profile.GetProfileGroup(ProfileConnectionStrings)[connName].ToString();
        }

        public static string GetRHStockConnection(DateTime workDate){
            string connString = WebConfigurationManager.ConnectionStrings["RH_StockConnectionString"].ConnectionString;
            return connString.Replace("2009", workDate.Year.ToString());
        }
    }
}